package org.boyan.modules.service;

import org.boyan.common.util.UUIDGenerator;
import org.boyan.entity.trans.Trans;
import org.boyan.modules.mapper.CaseTransRelationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class CaseTransRelationServiceImpl implements CaseTransRelationService{
    @Autowired
    private CaseTransRelationMapper caseTransRelationMapper;

    @Override
    @Transactional
    public boolean addRelation(String id, List<Trans> transList) {
        boolean flag=true;
        for(Trans trans:transList){
            //给relation添加一个流水号
            String uuid= UUIDGenerator.generate();
            if(caseTransRelationMapper.addRelation(uuid,id,trans.getId())!=1){
                flag=false;
                break;
            }
        }
        return flag;
    }

    @Override
    public boolean deleteRelationsByCaseId(String id) {
        int total=caseTransRelationMapper.getCaseRelationsByCaseId(id);
        return caseTransRelationMapper.delRelationsByCaseId(id)==total;
    }
}
